package hpu.bitenergy.servlet;

import hpu.bitenergy.Factory.Factory;
import hpu.bitenergy.IFactory.IFactory;
import hpu.bitenergy.List.GetList;
import hpu.bitenergy.util.QueryHelper;
import hpu.bitenergy.util.StringHelper;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.jasper.tagplugins.jstl.core.Out;

import com.mongodb.DBObject;

public class expert_ZFTservlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String expert_name=new String(request.getParameter("expert_name").getBytes("ISO_8859-1"), "UTF-8");		
		System.out.println(expert_name+"收到");
		List<DBObject> expertinfolist=new ArrayList<DBObject>();
		//通过专家名查合作者  直方图
		IFactory fa=Factory.GetIFactory("L");		
		GetList li=fa.GetListInstance();
		List<DBObject> list=li.getQueryList(QueryHelper.expert_name(StringHelper.AddOneKong(expert_name.trim())),QueryHelper.author_cn(true));	
		System.out.println(list+"合作者");
		List<String> name=StringHelper.GetAuther_nameList(list,expert_name.trim());
		System.out.println(name+"合作者名字");
		//String [] namelist =name.split(",");
		for(int i=0;i<name.size();i++){
		System.out.println(name.get(i)+"姓名");//所有合作者
		//通过合作者名字查其信息
		IFactory fac=Factory.GetIFactory("E");		
		GetList lis=fac.GetListInstance();
		List<DBObject> expertinfo=lis.getQueryList(QueryHelper.expert_name(StringHelper.AddTwoKong(name.get(i).trim())));
		if(expertinfo!=null)
		expertinfolist.addAll(expertinfo);
		System.out.println(expertinfo);		
		}
		System.out.println("直方图"+expertinfolist+"ok");
		
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		PrintWriter out=response.getWriter();
		out.print(expertinfolist);
		out.flush();
		out.close();
	}

}
